package com.snail.billing.fragment;

import android.view.View;
import android.widget.TextView;

import com.android.os.Page;
import com.android.util.ResUtil;
import com.snail.billing.BillingLogic;
import com.snail.billing.LoginCallback;
import com.snail.billing.Resource;

public class LaunchFragment extends Page implements View.OnClickListener {

	private TextView textTitle;
	private View buttonBack;

	private View button1;
	private View button2;
	private View button3;

	@Override
	public int createLayoutId() {
		return ResUtil.getLayoutId(Resource.layout.snailbilling_launch_activity);
	}

	@Override
	public void onCreate() {
		super.onCreate();
		textTitle = (TextView) findViewById(ResUtil.getViewId(Resource.id.snailbilling_title_text));
		textTitle.setText(ResUtil.getString(Resource.string.snailbilling_launch_title));
		buttonBack = findViewById(ResUtil.getViewId(Resource.id.snailbilling_title_button_back));
		buttonBack.setOnClickListener(this);
		//
		button1 = findViewById(ResUtil.getViewId(Resource.id.snailbilling_launch_button1));
		button2 = findViewById(ResUtil.getViewId(Resource.id.snailbilling_launch_button2));
		button3 = findViewById(ResUtil.getViewId(Resource.id.snailbilling_launch_button3));
		button1.setOnClickListener(this);
		button2.setOnClickListener(this);
		button3.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		if (v.equals(buttonBack)) {
			getPageManager().backward();
		} else if (v.equals(button1)) {
			//
			BillingLogic logic = new BillingLogic(getContext());
			logic.oneKeyLogin(new LoginCallback() {
				
				@Override
				public void onLoginCallback(String account, String pwd) {
					getPageManager().finish();
				}
			});
		} else if (v.equals(button2)) {
			getPageManager().forward(LoginFragment.class);
		} else if (v.equals(button3)) {
			getPageManager().forward(RegisterFragment.class);
		}
	}

}
